
from PIL import Image
 

class ImageEditor():
    image_path = ""
    image_object = None
    
    def __init__(self, image_path):
        self.image_path = image_path
        
    
    def open_image(self):
        self.image_object = Image.open(self.image_path)
    
    def replace_with(self, color_tuple, another_color_tuple):
        pixel = self.image_object.load()
        for y in range(self.image_object.size[0]):
            for x in range(self.image_object.size[1]):
                pixel = self.image_object.load()
                red = pixel[y,x][0]
                green = pixel[y,x][1]
                blue = pixel[y,x][2]
                if red == color_tuple[0] and green == color_tuple[1] and blue == color_tuple[2]:
                    pixel[y,x] = another_color_tuple  
        self.image_object.save(self.image_path)
        
    def location_pixels_contains(self, color_tuple):
        location_list = []
        for y in range(self.image_object.size[0]):
            for x in range(self.image_object.size[1]):
                pixel = self.image_object.load()
                red = pixel[y,x][0]
                green = pixel[y,x][1]
                blue = pixel[y,x][2]
                if red == color_tuple[0] and green == color_tuple[1] and blue == color_tuple[2]:
                    location_list.append((x,y))
        return location_list
        
        
